/** init domain config */
import './config'

import Vue from 'vue'
import App from './App.vue'
import Storage from 'vue-ls'
import router from './router'
import store from './store/'
import { VueAxios } from "@/utils/request"
import * as echarts from 'echarts'
import VConsole from 'vconsole';
import Vant from 'vant'
import 'ant-design-vue/dist/antd.css';
import { Table, Tree, Input, TreeSelect, Pagination, FormModel, Select, Icon, Button, Spin  } from 'ant-design-vue';

import 'vant/lib/index.css'

import '@/permission' // permission control
import '@/utils/filter' // base filter
import SSO from '@/cas/sso.js'
// import '@/components/lazy_vant.js'
import '@/plugin/vxe-table.js'

import {
  ACCESS_TOKEN, USER_INFO
} from "@/store/mutation-types"

import hasPermission from '@/utils/hasPermission'
//表单验证
import { rules } from '@/utils/rules'
import { open } from '@/utils/router'
import { removeWatermark, setWaterMark } from './utils/watermark.js'
import moment from 'moment'

Vue.prototype.$echarts = echarts
Vue.prototype.rules = rules
Vue.prototype.$open = open
Vue.config.productionTip = false
Vue.use(Vant)
Vue.use(Table)
Vue.use(Tree)
Vue.use(TreeSelect)
Vue.use(Input)
Vue.use(Pagination)
Vue.use(FormModel)
Vue.use(Select)
Vue.use(Icon)
Vue.use(Button)
Vue.use(Spin)
Vue.use(VueAxios, router)
Vue.use(hasPermission)
Vue.use(Storage);


SSO.init(() => {
  main()
})
function main() {
  new VConsole();
  let intervalId
  new Vue({
    router,
    store,
    mounted() {
      store.commit('SET_TOKEN', Vue.ls.get(ACCESS_TOKEN))
      if (Vue.ls.get(ACCESS_TOKEN)) {
        intervalId = setInterval(() => {
          // console.log("🚀 userInfo:", localStorage.getItem('Login_Userinfo'))
          let userInfo = localStorage.getItem('Login_Userinfo')
            ? JSON.parse(localStorage.getItem('Login_Userinfo')).value
            : {}
          let str = userInfo.username + '-' + userInfo.realname
          let time = moment(new Date()).format('YYYY-MM-DD HH:mm:ss')
          setWaterMark(str, time)
        }, 1000)
      }
    },
    beforeDestroy() {
      if (intervalId) {
        clearInterval(intervalId)
      }
    },
    render: h => h(App)
  }).$mount('#app')
}